#include "actionfall.h"
#include "actionwalk.h"

ActionFall::ActionFall(Lem* lem) : Action(lem)
{
	m_action_name = LEM_ACTION_FALL;

	Animation anim(lem->get_graphics(), STANDARD_LEM_WIDTH, STANDARD_LEM_HEIGHT, STANDARD_FALL_ANIMATION_X,
		STANDARD_FALL_ANIMATION_Y, STANDARD_FALL_ANIMATION_LENGTH, STANDARD_FALL_ANIMATION_TIME);
	m_sprite = new Sprite(anim, true);
}

ActionFall::~ActionFall()
{
	delete m_sprite;
}

void ActionFall::Update(float timing_factor)
{
	// Walk speed is defined here.
	m_lem->set_y(m_lem->y() + 0.2f * timing_factor);

	if (m_lem->level()->GetGroundMaskValue(m_lem->x() + STANDARD_LEM_WIDTH * 0.5 + 0.5, m_lem->y() + STANDARD_LEM_HEIGHT + 0.5) != GroundMask::AIR)
		m_lem->SetNextAction(new ActionWalk(m_lem));

	m_sprite->Update(timing_factor);
}

void ActionFall::Draw()
{
	// Round correctly.
	m_sprite->set_x(m_lem->x() + 0.5);
	m_sprite->set_y(m_lem->y() + 0.5);

	m_sprite->Draw();
}